<? session_start();
						
include_once ('core/conn.php');
						
$db = get_conn();
						
check_session();
						
						
					
?>
					
					
<html>
					
<head>
<link href="tools/modal/base.css" type="text/css" rel="stylesheet" />
<link href="tools/modal/modal-window.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" lang="javascript" src="tools/modal/jquery-1.3.2.min.js"></script>
<script type="text/javascript" lang="javascript" src="tools/modal/modal-window.min.js"></script>
					
<script>
	function refresh_cars(id_location,layer){
		url = "ajax_comps/helper/cars.php?id="+id_location+"&layer="+layer; 
		$("#"+layer).load(url);	
	}
	
	function refresh_residents(id_location,layer){
		url = "ajax_comps/helper/residentes.php?id="+id_location+"&layer="+layer; 
		$("#"+layer).load(url);	

		url = "ajax_comps/helper/dueno.php?id="+id_location+"&layer="+layer; 
		$("#own_"+id_location).load(url);	
	}						

					

</script>					
</head>									
					
<body>														
				
				
<form name='locations' method='post' action='/core/locations.php' onsubmit='return checkdata(this)'>
				
<table width='100%' border='0'>
				  
	<tr>
	  <td valign='top'><a href="locations_form.php">Crear Nueva Fileal</a></td>
    </tr>
	<tr>
					
		<td valign='top'>
		<? 
			
		$sql = "select l.id_location , number, acc_id
				from locations l
				order by id_location";
			
		$result = mysql_query($sql);
			
		if($result){
				
			$data ="<table width='100%' border='1'>";
			$data .="<tr>
									
				<td align='left' >
					Casa
				</td>
				<td align='left' >
					Num. Cta
				</td>				

				<td align='left' >
					Residentes
				</td>
				<td align='left' >
					Vehiculos
				</td>				
				<td align='left' >
					Cobros<br>Pendientes
				</td>

				<td align='left' >
					Pagos<br>Pendientes
				</td>
				
				<td align='left' >
					Opciones
				</td>				
								  
				</tr>";				
			if(mysql_num_rows($result) > 0){
					
				while($row = mysql_fetch_array($result)){
					$controls ="<a href='invoices.php?filter=".$row['id_location']."' title='Crear nuevo cobro'><img src='images/dolar.gif' border='0'></a>";
					$controls .="&nbsp;<a href='#' title='Enviar mensaje privado'><img src='images/email.png' border='0'></a>";					
					$pending_invoices = get_pending_invoices_count($row['id_location']);
					if($pending_invoices >0){
						$pending_invoices_link = "<a href='history_admin.php?id_location=".$row['id_location']."&t=ip'>".$pending_invoices."</a>";	
					}else{
						$pending_invoices_link="Ninguna";
					}
					
					$pending_payments = get_pending_payments_count($row['id_location']);
					if($pending_payments >0){
						$pending_payments_link = "<a href='history_admin.php?id_location=".$row['id_location']."&t=pp'>".$pending_payments."</a>";	
					}else{
						$pending_payments_link = "Ninguna";		
					}					
					$data .="<tr style='border:1px solid #000'>
						<td align='left' >
							<a href='locations_form.php?id=".$row['id_location']."'>".$row['number']."</a>
						</td>
						<td align='left' >
							".$row['acc_id']."
						</td>						
						<td align='left' >
							".get_residents_sumary($row['id_location'])."
						</td>	
						<td align='left' >
							".get_vehicules_sumary($row['id_location'])."
						</td>
						<td align='left' >
							".$pending_invoices_link." 
						</td>	
						<td align='left' >
							".$pending_payments_link." 
						</td>
						<td align='left' >
							$controls
						</td>												
						</tr>";
					
				}//while
				
			}//if
				
			else{
					
				$data .= "<tr><td align='center'>No hay locations registrados</td></tr>";			
				
			}
				
			$data .="</table>";
			
		}else{
				
			error_handling($sql,mysql_error());
			
		}
			
		echo $data;
			
		?>&nbsp;</td>
						
	</tr>
					
</table>
</form>
					
</body></html>													
					